home *** CD-ROM | disk | FTP | other *** search
/ Aminet 32 / Aminet 32 (1999)(Schatztruhe)[!][Aug 1999].iso / Aminet / dev / lang / Python151_Src.lha / Python1.5_Source / Amiga / gettimeofday.c < prev    next >
C/C++ Source or Header  |  1998-12-25  |  3KB  |  106 lines

  1. RCS_ID_C="$Id: gettimeofday.c,v 4.1 1994/09/29 23:09:02 jraja Exp $"
  2. /*
  3.  *      gettimeofday.c - get time of the day
  4.  *
  5.  *      Copyright © 1994 AmiTCP/IP Group, 
  6.  *                       Network Solutions Development Inc.
  7.  *                       All rights reserved.
  8.  */
  9.  
  10. #include <sys/param.h>
  11. #include <time.h>
  12. #include <sys/time.h>
  13.  
  14. #include <proto/timer.h>
  15.  
  16. /****** net.lib/gettimeofday *********************************************
  17.  
  18.     NAME   
  19.         gettimeofday - get date and time 
  20.  
  21.     SYNOPSIS
  22.         #include <sys/time.h>
  23.  
  24.         error = gettimeofday(tp, tzp)
  25.  
  26.         int gettimeofday(struct timeval *, struct timezone *)
  27.  
  28.     FUNCTION
  29.         The system's notion of the current Greenwich time and the
  30.         current time zone is obtained with the gettimeofday() call.
  31.         The time is expressed in seconds and microseconds since
  32.         midnight (0 hour), January 1, 1970.  The resolution of the
  33.         system clock is hardware dependent. If tzp is zero, the time
  34.         zone information will not be returned. Also, if your system
  35.         software is unable to provide time zone information, the
  36.         structure pointed by tzp will be filled with zeroes.
  37.    
  38.     PORTABILITY
  39.         UNIX
  40.  
  41.     INPUTS
  42.         The structures pointed to by tp and tzp are defined in
  43.         <sys/time.h> as:
  44.    
  45.              struct timeval {
  46.                   long tv_sec;      \* seconds since Jan. 1, 1970 *\
  47.                   long tv_usec;     \* and microseconds *\
  48.              };
  49.    
  50.              struct timezone {
  51.                   int  tz_minuteswest;   \* of Greenwich *\
  52.                   int  tz_dsttime;  \* type of dst correction to apply *\
  53.              };
  54.    
  55.         The timezone structure indicates the local time zone (meas-
  56.         ured in minutes of time westward from Greenwich), and a flag
  57.         that, if nonzero, indicates that Daylight Saving time
  58.         applies locally during the appropriate part of the year.
  59.  
  60.     RESULT
  61.         Returns 0 when successful and -1 with specific error code in 
  62.         errno in case of an error. No error codes are specified,
  63.         however.
  64.         
  65.     NOTES
  66.         gettimeofday() uses GetSysTime() function of the timer.device,
  67.         which is new to V36 of the device.
  68.  
  69.         Time zone information is taken from the locale.library, if it
  70.         is available (it is included in all Amiga systems from 2.1 and
  71.         up). Otherwise the environment variable "TZ" is consulted. If
  72.         it fails, the time zone is initialized to the GMT.
  73.  
  74.         Global variable TimerBase _must_ be initialized before
  75.         gettimeofday() is called. This is normally done automatically
  76.         by the autoinit module (timerinit.c) included in the net.lib.
  77.  
  78.     SEE ALSO
  79.         timer.device/GetSysTime()
  80. *****************************************************************************
  81. *
  82. */
  83.  
  84. /*
  85.  * See timerinit.c for comments on these
  86.  */
  87. extern struct timezone __time_zone;
  88. extern long __local_to_GMT;
  89.  
  90. int 
  91. gettimeofday(struct timeval *tp, struct timezone *tzp)
  92. {
  93.   if (tp) {
  94.     GetSysTime(tp);
  95.     tp->tv_sec += __local_to_GMT;
  96.   }
  97.   if (tzp) {
  98.     /*
  99.      * __time_zone is set up in the timerinit.c
  100.      */
  101.     *tzp = __time_zone;
  102.   }
  103.  
  104.   return 0;
  105. }
  106.